package gim_client

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

func RunHttp(port int) {

	Logger.Infof("gim-tcpClient http server success on %d", port)
	Logger.Error(initServer(fmt.Sprintf(":%d", port), routers()).ListenAndServe().Error())
}

func routers() *gin.Engine {

	engine := gin.Default()
	group := engine.Group("")
	{
		// 健康监测
		group.GET("/health", func(c *gin.Context) {
			c.JSON(200, "ok")
		})
		InitChatApi(group) // 聊天api
	}
	return engine
}

func initServer(address string, router *gin.Engine) *http.Server {
	return &http.Server{
		Addr:           address,
		Handler:        router,
		ReadTimeout:    20 * time.Second,
		WriteTimeout:   20 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
}
